package com.jari.lg.service.profile.area;

import com.jari.lg.domain.CheckPointHisEntity;
import com.jari.lg.domain.DevBase;
import com.jari.lg.mapper.CheckPointHisEntityMapper;
import com.jari.lg.utils.BaseData;
import com.jari.lg.utils.Constants;
import com.jari.lg.utils.UUIDUtils;
import com.jari.lg.utils.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import sun.plugin.util.UIUtil;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class CheckPointHisImpl {

    @Autowired
    private CheckPointHisEntityMapper checkPointHisEntityMapper;

    /*
    *  每分钟每个卡口设置1辆汽车通过信息
    * */
    @Scheduled(cron = "* */1 * * * ?")
    public void makeCheckPointHisInfo(){
        List<CheckPointHisEntity> result = new ArrayList<>();
        List<DevBase> checkpointList = BaseData.checkpointList;
        for(DevBase tmp : checkpointList){
            result.add(generateInfo(tmp));
        }
        checkPointHisEntityMapper.insertBatch(result);
    }

    /*
    * 构造具体的表对象
    * */
    private CheckPointHisEntity generateInfo(DevBase base){
        CheckPointHisEntity entity = new CheckPointHisEntity();
        String plateNum = Utils.createPlateNumber();
        entity.setPlatenumber(plateNum);
        entity.setCartype(Utils.createPlateType());
        entity.setCheckpointcode(base.getDevicecode());
        entity.setCreator("SYS");
        entity.setDatastatus(Constants.DATA_STATUS_ONE);
        entity.setGmtcreate(new Date());
        entity.setDatetime(new Date());
        entity.setId(UUIDUtils.getUUIDFormat());
        entity.setPlatetype(Utils.createPlateType());
        return entity;
    }

}
